//
//  ViewControllerChooser.m
//  iFlickr
//
//  Created by 张 霄鹤 on 09-5-17.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "ViewControllerChooser.h"

// 工厂模式
static ViewControllerChooser *outInstance;

@implementation ViewControllerChooser


+(id)alloc{
	outInstance = [super alloc];
	return outInstance;
}

-(id)init{
	if(self = [super init]){
	}
	return self;
}

+(id)sharedChooser{
	if(outInstance == nil){
		outInstance = [[ViewControllerChooser alloc] init];
	}
	return outInstance;
}


-(UIViewController *)choose:(NSInteger)vid{
	// 对于下面的赋值操作，不能够使用autorealse方式 ！！
	UIViewController *ret = nil;
	switch (vid) {
		case VCC_ID_AUTH:
			if(authVC == nil){
				authVC = [[AuthViewController alloc] initWithNibName:@"AuthViewController" bundle:nil];
			}
			ret = [authVC retain];
			break;
		case VCC_ID_UPLOAD:
			if(uploadVC == nil){
				uploadVC = [[UploadViewController alloc] initWithNibName:@"UploadViewController" bundle:nil];
			}
			ret = [uploadVC retain];
			break;
		case VCC_ID_ABOUT:
			if(aboutVC == nil){
				aboutVC = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];
			}
			ret = [aboutVC retain];
			break;
		case VCC_ID_EDIT:
			if(editVC == nil){
				editVC = [[ItemEditViewController alloc] initWithNibName:@"ItemEditViewController" bundle:nil];
			}
			ret = [editVC retain];
			break;
		case VCC_ID_SHARE:
			if(shareVC == nil){
				shareVC = [[SendViewController alloc] initWithNibName:@"SendViewController" bundle:nil];
			}
			ret = [shareVC retain];
			break;
		case VCC_ID_PROGRESS:
			if(progressVC == nil){
				progressVC = [[ProgressViewController alloc] initWithNibName:@"ProgressView" bundle:nil];
			}
			ret = progressVC;
			break;
		case VCC_ID_PHOTOSETS:
			if(photosetVC == nil){
				photosetVC = [[PhotosetViewController alloc] initWithNibName:@"PhotosetViewController" bundle:nil];
			}
			ret = photosetVC;
			break;
		case VCC_ID_PHOTOSET_ADD:
			if(photosetAddVC == nil){
				photosetAddVC = [[PhotosetAddViewController alloc] initWithNibName:@"PhotosetAddViewController" bundle:nil];
			}
			ret = photosetAddVC;
			break;


		default:
			break;
	}
	return ret;
}

-(void)dealloc{
	if(authVC != nil){
		[authVC release];
	}
	if(uploadVC != nil){
		[uploadVC release];
	}
	if(aboutVC != nil){
		[aboutVC release];
	}
	if(editVC != nil){
		[editVC release];
	}
	if(shareVC != nil){
		[shareVC release];
	}
	if(progressVC != nil){
		[progressVC release];
	}
	if(photosetVC != nil){
		[photosetVC release];
	}
	if(photosetAddVC != nil){
		[photosetAddVC release];
	}
	[super dealloc];
}

@end
